﻿Imports System.Data.SqlClient

Public Class frmSelectUser

    Sub FillUsers()
        Try
            Me.Cursor = Cursors.WaitCursor

            Dim cmd As New SqlCommand("Select SNo,FullName From Users Order By SNo", cnn)
            Dim Reader As SqlDataReader

            Me.ListUsers.Items.Clear()

            cnn.Open()
            Reader = cmd.ExecuteReader
            While Reader.Read
                Dim Item As New ListViewItem
                Item.Text = Reader.Item("SNo")
                Item.SubItems.Add(Reader.Item("FullName"))
                Me.ListUsers.Items.Add(Item)
            End While
            cnn.Close()

            Me.Cursor = Cursors.Default
        Catch ex As Exception
            Me.Cursor = Cursors.Default
            MsgBox(ex.ToString)
            If cnn.State = ConnectionState.Open Then
                cnn.Close()
            End If
        End Try
    End Sub

    Private Sub frmSelectUser_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        FillUsers()

        SelUserID = ""
    End Sub

    Private Sub ListUsers_DoubleClick(sender As System.Object, e As System.EventArgs) Handles ListUsers.DoubleClick
        If Me.ListUsers.SelectedItems.Count > 0 Then
            SelUserID = Me.ListUsers.SelectedItems(0).Text
            Me.Close()
        End If
    End Sub
End Class